import axios from 'axios';
import qs from 'qs'

// 这是线上开发的URL
export const baseURL = "http://cyq.center:8000";


// 首页上歌曲的推荐
export const getSongRecommend = () => {
    const url = `${baseURL}/recommend/song`;
    return axios.get(url,{withCredentials:true})
};

//获取轮播图
export const getSongBanner = () =>{
    const url = `${baseURL}/recommend/bannerSongs`;
    return axios.get( url,{ withCredentials: true } )
};

// 获取单曲得评论数据
export const getSongComment = (id, limit=20, offset=1) => {
    let url = "";
    if(offset){
        url = `${baseURL}/comment/music?id=${id}&limit=${limit}&offset=${offset}`;
    }else {
        url = `${baseURL}/comment/music?id=${id}`;
    }
    return axios.get(url,{ withCredentials: true });
};

// 获取单曲歌词
export const getSongLyric = (id) => {
    const url = `${baseURL}/lyric?id=${id}`;
    return axios.get(url,{ withCredentials: true });
};

// 评论歌曲
export const setSongComment = (userId, comment, time, songId) => {
    const url = `${baseURL}/setSongComment`;
    return axios.get(url,{
        params:{
            userId: userId,
            comment: comment,
            time: time,
            songId: songId
        }
    },{ withCredentials: true });
};

// 评论歌曲
export const setMvComment = (userId, comment, time, mvId) => {
    const url = `${baseURL}/setMvComment`;
    return axios.get(url,{
        params:{
            userId: userId,
            comment: comment,
            time: time,
            mvId: mvId
        }
    },{ withCredentials: true });
};

// 获取单曲歌词
export const getMvById = (id) => {
    const url = `${baseURL}/mvDetail?id=${id}`;
    return axios.get(url,{ withCredentials: true });
};

// 所有榜单数据 即歌曲总页
export const alltopListData = (type, limit=20, offset=1) => {
    const url = `${baseURL}/discover/toplist?type=${type}&limit=${limit}&offset=${offset}`;
    return axios.get(url,{ withCredentials: true });
};


// 请求各个类型歌手数据
export const getSingerTypeData = (url, limit, offset) => {
    if(limit) {
        return axios.get(`${baseURL}${url}&limit=${limit}`,{ withCredentials: true });
    }else if(limit && offset) {
        offset = limit*(offset-1);
        return axios.get(`${baseURL}${url}&limit=${limit}&offset=${offset}`,{ withCredentials: true })
    }
    return axios.get(`${baseURL}${url}`,{ withCredentials: true })
};

// 获取用户的歌单
export const getSongSheetByUserId = (userId) => {
    const url =`${baseURL}/songSheet?userId=${userId}`;
    return axios.get(url,{ withCredentials: true });
};

// 收藏歌曲到歌单
export const setSongSheet = (sheetId, songId) => {
    const user = localStorage.getItem("loginObj");
    const userId = JSON.parse(user)['userId'];
    const url =`${baseURL}/setSongSheet?sheetId=${sheetId}&songId=${songId}&userId=${userId}`;
    return axios.get(url,{ withCredentials: true });
};

// 歌曲的播放数据
export const getSongUrlData = (id) => {
    const url = `${baseURL}/song/url?id=${id}`;
    return axios.get(url,{ withCredentials: true })
};

// 获取单曲详细数据
export const getSongData = (id) => {
    const url =`${baseURL}/song/detail?id=${id}`;
    return axios.get(url,{ withCredentials: true });
};

// 点赞mv
export const starMv = (userId, mvId) => {
    const url =`${baseURL}/starMv?userId=${userId}&mvId=${mvId}`;
    return axios.get(url,{ withCredentials: true });
};

// 收藏mv
export const collectMv = (userId, mvId) => {
    const url =`${baseURL}/collectMv?userId=${userId}&mvId=${mvId}`;
    return axios.get(url,{ withCredentials: true });
};

// 发送弹幕
export const sendBarrage = (value, startTime, mvId) => {
    const url =`${baseURL}/sendBarrage?value=${value}&startTime=${startTime}&mvId=${mvId}`;
    return axios.get(url,{ withCredentials: true });
};

// 发送邮箱注册验证码
export const getMailCode = (registerMail) =>{
    const url =`${baseURL}/registerVerifyCode`;
    return axios.get(url,{
        params:{
            registerMail:registerMail,
        }
    },{ withCredentials:true });
};

// 验证邮箱注册验证码
export  const checkMailCode = (registerMail,registerVerifyCode) =>{
    const url = `${baseURL}/checkVerifyCode`;
    return axios.get(url,{
        params:{
            registerVerifyCode:registerVerifyCode,
            registerMail:registerMail,
        },
        headers:{
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    }, { withCredentials:true,response:"" });
};

// 邮箱注册
export const registerByMail = (nickname,gender,registerPassword,registerMail) => {
    const url = `${baseURL}/register/mail`;
    return axios.get(url,{
        params:{
            nickname:nickname,
            gender:gender,
            registerPassword:registerPassword,
            registerMail:registerMail,
        }
    }, { withCredentials:true });
};

// 登录
export const login = (loginMail,loginPassword) => {
    console.log(loginMail)
    const url = `${baseURL}/login/mail`;
    return axios.get(url,{
        params:{
            loginMail: loginMail,
            loginPassword: loginPassword,
        }
    }, { withCredentials:true });
};

// 获取推荐MV
export const recommendMV = (offset) => {
    const url = `${baseURL}/recommendmv`;
    return axios.get(url,{
        params:{
            limit: 12,
            offset:offset,
        }
    }, { withCredentials:true });
};

// 忘记密码
export const resetPasswordByMail = (resetVerifyMail,resetPassword) =>{
    const url = `${baseURL}/resetPassword`;
    return axios.get(url,{
        params:{
            resetVerifyMail: resetVerifyMail,
            resetPassword:resetPassword,
        }
    }, { withCredentials:true });
};

// 我的音乐->MV列表和歌单列表
export const myMusicMVAndSongList = (userId) =>{
    const url = `${baseURL}/myMusicDefault`;
    return axios.get(url,{
        params:{
            userId: userId,
        }
    }, { withCredentials:true });
};

// 我的音乐->所有MV信息
export const myMusicMVList = (userId) =>{
    const url = `${baseURL}/myMusicMVList`;
    return axios.get(url,{
        params:{
            userId: userId,
        }
    }, { withCredentials:true });
};

// 我的音乐->所有歌单信息
export const myMusicSongList = (userId,songListId) =>{
    const url = `${baseURL}/myMusicSongList`;
    return axios.get(url,{
        params:{
            userId: userId,
            songListId: songListId,
        }
    }, { withCredentials:true });
};

// 我的音乐->创建歌单
export const myMusicCreateSongList = (userId,songListName) =>{
    const url = `${baseURL}/myMusic/createSongList`;
    return axios.get(url,{
        params:{
            userId: userId,
            songListName: songListName,
        }
    }, { withCredentials:true });
};

// 我的音乐->编辑歌单
export const myMusicEditSongList = (userId,songListId,songListName) =>{
    const url = `${baseURL}/myMusic/editSongList`;
    return axios.get(url,{
        params:{
            userId: userId,
            songListId: songListId,
            songListName: songListName,
        }
    }, { withCredentials:true });
};

// 我的歌单->收藏歌曲export const setSongSheet = (sheetId, songId) => {
// 我的歌单->删除歌单
export const myMusicDeleteSongList = (userId,songListId) =>{
    const url = `${baseURL}/myMusic/deleteSongList`;
    return axios.get(url,{
        params:{
            userId: userId,
            songListId: songListId,
        }
    }, { withCredentials:true });
};

// 我的歌单->删除歌曲
export const myMusicRemoveSong = (userId,songListId,songId) =>{
    const url = `${baseURL}/myMusic/songList/removeSong`;
    return axios.get(url,{
        params:{
            userId: userId,
            songListId: songListId,
            songId: songId,
        }
    }, { withCredentials:true });
};

// 我的歌单->删除MV
export const myMusicDeleteMV = (mvId) =>{
    const url = `${baseURL}/myMusic/deleteMV`;
    const user = localStorage.getItem("loginObj");
    const userId = JSON.parse(user)['userId'];
    return axios.get(url,{
        params:{
            userId: userId,
            mvId: mvId,
        }
    }, { withCredentials:true });
};

// 获取设置信息
export const getSettingData = (uid) => {
    const url = `${baseURL}/setting?id=${uid}`;
    return axios.get(url,{withCredentials:true})
};

// 设置设置信息
export const setSettingData = (userId,username, sex, userEmail, phone,imgUrl) => {
    const url = `${baseURL}/setSettingData`;
    let data;
    if(imgUrl){
        data={
            userId:userId,
            username:username,
            sex:sex,
            userEmail:userEmail,
            phone:phone,
        }
    }else{
        data={
            userId:userId,
            username:username,
            sex:sex,
            userEmail:userEmail,
            phone:phone,
        }
    }

    return axios.post(url,qs.stringify(data),{ withCredentials: true });

};

// 获取用户等级信息
export const getUserLevelData = (uid) => {
    const url = `${baseURL}/user/level?id=${uid}`;
    return axios.get(url,{withCredentials:true})
};

// 获取歌手个人信息
export const getArtistData = (id) => {
    const url = `${baseURL}/acquire/artist?id=${id}`;
    return axios.get(url,{ withCredentials: true });
};

// 获取热门歌手
export const getHotSingerData = (offset) => {
    const url = `${baseURL}/discover/artist/signed?offset=${offset}&limit=20`;
    return axios.get(url,{ withCredentials: true });
};

export const getCatSingerData = (id, initial,offset) => {
    if(initial) {
        let url = `${baseURL}/discover/artist/cat?id=${id}&&initial=${initial}&&offset=${offset}&limit=20`;
        return axios.get(url,{ withCredentials: true })
    }else {
        let url = `${baseURL}/discover/artist/cat?id=${id}&&offset=${offset}&limit=20`;
        return axios.get(url,{ withCredentials: true })

    }
};